<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@taglib prefix="s" uri="/struts-tags"%>
<%
	String path = request.getContextPath();
	String basePath = request.getScheme() + "://"
			+ request.getServerName() + ":" + request.getServerPort()
			+ path + "/";
%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
	<head>
		<base href="<%=basePath%>"  target="_self">

		<title>学生高级查询</title>
	
		<link rel="stylesheet"
			href="<%=request.getContextPath()%>/css/common.css" type="text/css" />
		
		<link rel="stylesheet"
			href="<%=request.getContextPath()%>/css/style.css" type="text/css" />
	
		<script type='text/javascript'
			src='<%=request.getContextPath()%>/js/sorttable.js'></script>
		<script type='text/javascript'
			src='<%=request.getContextPath()%>/dwr/interface/dWRCollegeMajorAction.js'></script>
		<script type='text/javascript'
			src='<%=request.getContextPath()%>/dwr/interface/dormitoryAllocateAction.js'></script>
		<script type='text/javascript'
			src='<%=request.getContextPath()%>/dwr/interface/apartmentViewAction.js'></script>
		<script type='text/javascript'
			src='<%=request.getContextPath()%>/dwr/interface/studentAction.js'></script>
		<script type='text/javascript'
			src='<%=request.getContextPath()%>/dwr/interface/studentLodgeMgrAction.js'></script>
		<script type='text/javascript'
			src='<%=request.getContextPath()%>/dwr/engine.js'></script>
		<script type='text/javascript'
			src='<%=request.getContextPath()%>/dwr/util.js'></script>
		<script type='text/javascript'
			src='<%=request.getContextPath()%>/js/jquery-latest.pack.js'></script>
		<script type="text/javascript"
			src="<%=request.getContextPath()%>/js/jqueryCopyEvent.js"></script>
		<script type="text/javascript"
			src="<%=request.getContextPath()%>/js/jquery.corner.js"></script>
		<script type='text/javascript'
			src='<%=request.getContextPath()%>/js/noConflictOfJquery.js'></script>
		<script type='text/javascript'
			src='<%=request.getContextPath()%>/js/forCSS.js'></script>
		<script type='text/javascript'>
		
/*********************执行流程**************************
说明：id为item的div默认隐藏，当添加一个id为item的div时克隆它
初始化页面：克隆一个id为item的div，并显示,即增加一组查询条件


******************************************************/
var xmlHttp = null;
		var flag = 1;
		var eventObj = null;
		var lastFlag = false;
		var resConnectors = null;
		var selectedObj = null;
		var responseFlag = false;//标识是否有响应
		var connectors = new Array();//存储已经选择的联系人
		var userSelectNos = null;
		var selectedPhones = null;//记录已经选择的联系人(存储在父窗体中)
		var currIndex = -1;//当前项索引
		var currPage = 1;//当前页码
		var pageNum = 0;//总页数
		var pageSize = 8;//每页显示的数目
		var isUp = false;//标识上翻
		var isDown = false;//标识下翻
		var keywordRecord = null;
		var firstInputFlag = true;
		
		function initXmlHttpReq(){
			var args = ["Msxml2.XMLHTTP","Msxml3.XMLHTTP","Microsoft.XMLHTTP"];
			if(xmlHttp == null){
				for(var i = 0, j = args.length; i<j; i++){
					xmlHttp = new ActiveXObject(args[i]);
					
					if(xmlHttp)
						return;
				}
				
				xmlHttp = new XMLHttpRequest();
			}
		}
		
		
//===================全局变量=====================
		var sql;   //传到后台的sql语句
		var itemCount = 0;  //查询条件的组数,隐藏的不算
		var aptInfo;  //公寓的所有信息
		var apartamount ;//给公寓总条数赋值
		var sidList = new Array();//学生id数组
		var stelList = new Array();
		var totalCount = -1; //查询到的总行数
		var stuCache = { }; 
		
//----------------------全局变量定义结束-----------------





//=========================页面初始化=====================
		 $j(function(){
		 	showAllCollege( $j(".seleCollege").get(0));//学院列表
		 	showAllMajor($j(".seleMajor").get(0));//专业列表
		 	setApartList($j(".seleApartment").get(0));//公寓列表
		 	//$j(".divItem").corner("sc:#cccccc");//圆角
		 	setAllocationInfo($j(".seleStudentLabel").get(0));//载入预分配allcationinfo的内容
		 	
		 	newItem("#item","#condition");//克隆id为item的div，并显示
		 	
		 	
		 	
		 });
//-----------------------页面初始化结束-------------------		





//==========================自定义函数====================
		//增加一组查询条件，即克隆id为item的div，并显示
		function newItem(copyed,appended){
			var item = $j(copyed).cloneWithEvents();
			item.get(0).style.display = "";
			item.appendTo(appended);
			itemCount++;
			$j(".divItem").corner("sc:#cccccc");//圆角
		}
		//删除一组查询条件
		function deleteItem(obj){
			if(itemCount == 1){
				return;
			}
			$j(obj).parent().parent().remove();
			itemCount--;
			$j(".divItem").corner("sc:#cccccc");//圆角
		}
		//显示所有的学院
		function showAllCollege(collegeObj){
			DWREngine.setAsync(false);  //dwr同步
			dWRCollegeMajorAction.getAllCollegeInfo(function (collegeList){
					if(null == collegeList){
						return;
					}
					var collegeInfo =collegeList;
					var s =collegeObj;
					 	DWRUtil.removeAllOptions(s);  
						s.options[0] = new Option("不限学院",'0');
						//alert(collegeList[0].collegeinfoname)
					for ( var i = 1; i < collegeList.length+1; i++) {
						var opt = new Option(collegeList[i-1].collegeinfoname,
								collegeList[i-1].collegeinfoid);
						s.options[i] = opt;
					}
			});
			DWREngine.setAsync(true);  //恢复dwr异步
		}
		
		//显示所有的专业,obj为显示下拉列表元素
		function showAllMajor(obj){
			DWREngine.setAsync(false);  //dwr同步
			dWRCollegeMajorAction. getAllMajorInfo(function (majorList){
					if(null == majorList){
						return;
					}
					var majorInfo =majorList;
					//alert(aptValue[0].apartmentfloornum);
					var s = obj;
					 	DWRUtil.removeAllOptions(s);  
						s.options[0] = new Option("不限专业",'0');
						//alert(majorList[0].majorinfoname)
					for ( var i = 1; i < majorList.length+1; i++) {
						var opt = new Option(majorList[i-1].majorinfoname,
								majorList[i-1].majorinfoid);
						s.options[i] = opt;
					}
			});
			DWREngine.setAsync(true);  //恢复dwr异步
		}
		//选择的学院变动的时候，专业联动 
		function selectedCollegeChange(collegeObj){
			majorObj = $j(collegeObj).parent().find(".seleMajor").get(0);
			if(collegeObj.options[collegeObj.selectedIndex].value == '0'){
				showAllMajor(majorObj);
				return;
			}
			showMajorByCollegeinfoid(collegeObj,collegeObj.options[collegeObj.selectedIndex].value);
			
		}
		//根据学院显示所有的专业
		function showMajorByCollegeinfoid(obj,collegeinfoid){
			dWRCollegeMajorAction.getMajorInfoByCollegeId(collegeinfoid, function  (majorList){
				var s =$j(obj).parent().find(".seleMajor").get(0);
				if(majorList == null){
					DWRUtil.removeAllOptions(s); 
					s.options[0] = new
					 Option("不存在专业",'0');
					return;
				}
				var majorInfo =majorList;
				//alert(aptValue[0].apartmentfloornum);
				 	DWRUtil.removeAllOptions(s);  
					s.options[0] = new Option("不限专业",'0');
					//alert(majorList[0].majorinfoname)
				for ( var i = 1; i < majorList.length+1; i++) {
					var opt = new Option(majorList[i-1].majorinfoname,
							majorList[i-1].majorinfoid);
					s.options[i] = opt;
				}
			});
			
		}
		//选择的专业变动的时候，学院联动
		function selectedMajorChange(obj){
			major = obj;
			if(obj.options[obj.selectedIndex].value == '0'){
				return;
			}
			showCollegeByMajorInfoid(obj,obj.options[obj.selectedIndex].value);
		}
		//根据专业显示学院
		function showCollegeByMajorInfoid(obj,majorinfoid){
			dWRCollegeMajorAction.getCollegeInfoByMajorId(majorinfoid,function (collegeList){
				var college = $j(obj).parent().find(".seleCollege").get(0);
				for(var a=0;a<college.options.length;a++){
					if(college.options[a].value == collegeList[0].collegeinfoid){
						college.options[a].selected = "selected";
						break;
					}
				}
			});
		}
		//显示所有的公寓
		function setApartList(obj) {
			DWREngine.setAsync(false);  //dwr同步
			apartmentViewAction.getAllApartInfo(function (aptValue){
				aptInfo =aptValue;
				apartamount = aptInfo.length; //给公寓总条数赋值
				var s = $(obj);
			 	DWRUtil.removeAllOptions(s); 
				s.options[0] = new Option("不限公寓",'0');
				for ( var i = 1; i < aptValue.length+1; i++) {
					var opt = new Option(aptValue[i-1].apartmentname,aptValue[i-1].apartmentid);
					s.options[i] = opt;
				}
			});
			DWREngine.setAsync(true);  //恢复dwr异步
		}
		
		//公寓变动时触发，apartment是公寓select元素,floor是楼层select元素
		function apartmentChange(apartment){

			//apartmentid = $("aptName").options[$("aptName").selectedIndex].value; //给apartmentid赋值
			apartmentid = apartment.options[apartment.selectedIndex].value;
			//取到了对应apartmentid的楼层数目
			var aprt_floorno;
						var aprt_name;
						for(var m = 0; m<apartamount;m++){
							if(aptInfo[m].apartmentid ==apartmentid){
							aprt_floorno = aptInfo[m].apartmentfloornum;
							aprt_name = aptInfo[m].apartmentname;
							break;
							}
						}
						var sf = $j(apartment).parent().find(".seleFloorno").get(0);
						DWRUtil.removeAllOptions(sf);  
						sf.options[0] = new Option("不楼层",'0');
						if(aprt_name == "七号楼"){
						for ( var j = 1; j < (parseInt(aprt_floorno)-1); j++) {
							var optt = new Option((j+2)+"层",(j+2));
							sf.options[j] = optt;
						}
						}
						else if(aprt_name == "三号楼"){
						for ( var j = 1; j < (parseInt(aprt_floorno)); j++) {
							var optt = new Option((j+1)+"层",(j+1));
							sf.options[j] = optt;
						}
						}
						else{
						for ( var j = 1; j < (parseInt(aprt_floorno)+1); j++) {
							var optt = new Option(j+"层",j);
							sf.options[j] = optt;
						}
						
						}
		}
		//公寓状态当为空时,公寓列表和楼层列表和宿舍号都将不可用.
		function  DormStatusChange(status){
			var apartment = $j(status).parent().find(".seleApartment").get(0);
			var floor = $j(status).parent().find(".seleFloorno").get(0);
			var dormNum = $j(status).parent().find(".txtDorm").get(0);
			if(status.options[status.selectedIndex].value == "blank"){
				apartment.disabled = true;
				floor.disabled = true;
				dormNum.disabled = true;
			}else{
				apartment.disabled = false;
				floor.disabled = false;
				dormNum.disabled = false;
			}
		}
		//载入预分配allcationinfo的内容
		function setAllocationInfo(studentLabelObj){
			DWREngine.setAsync(false); 
			return dormitoryAllocateAction.getAllAllocationInfo(function (aiList){
				var sp = studentLabelObj;
				DWRUtil.removeAllOptions(sp);  
				sp.options[0] = new Option("学生预分配值",'0');
				for ( var i = 1; i < aiList.length+1; i++) {
					var opt = new Option(aiList[i-1].allocationname,
							aiList[i-1].allocationid);
					sp.options[i] = opt;
				}
				
			});
			DWREngine.setAsync(true); 
		}
		
		
		
		
		
		
		
		
		
		
		
		//查询按钮触发的事件
		function search(){
			sidList.length = 0;
			sql = "select * from student "
				+ "left join studentbedlink on studentbedlink.studentid = student.studentid "
				+ "left join dormitory on studentbedlink.dormitoryid=dormitory.dormitoryid "
				+ "where 0=1 ";
			
			for(var a = 1;a<=itemCount;a++){
				
				//---------------条件开始------------
				var q = $j(".divItem:eq("+a+")");
				var s = 0;//表示union后的左半括号是否存在，0为不存在；
				var an = 0;//表示条件前是否要加and，0表示不加；
				var tmp;
				//-------------学号
				tmp = $j.trim(q.find(".txtNo").get(0).value);
				if(tmp != ""){
					if(s == 0){
						sql += "or (";
						s = 1;  //表示union后的左半括号存在
						an = 1;//表示该条件之后的条件要加and
					}
					sql += "student.studentno like '%"+ tmp +"%'";
					
					
				}
				//-------------姓名
				tmp = $j.trim(q.find(".txtName").get(0).value);
				if(tmp != ""){
					if(an == 1){
						sql+=" and ";
						an = 1;
					}
					if(s == 0){
						sql += "or (";
						s = 1;  //表示union后的左半括号存在
						an = 1;//表示该条件之后的条件要加and
					}
					
					sql += "student.studentname like '%"+ tmp +"%'";
				}
				//-----------------性别
				tmp = $j.trim(q.find(".seleGender").get(0).options[q.find(".seleGender").get(0).selectedIndex].value);
				if(q.find(".seleGender").get(0).selectedIndex != '0'){
					if(an == 1){
						sql+=" and ";
						an = 1;
					}
					if(s == 0){
						sql += "or (";
						s = 1;  //表示union后的左半括号存在
						an = 1;//表示该条件之后的条件要加and
					}
					
					sql += "student.studentgender = '"+ tmp +"'";
				}
					//-----------------电话
				tmp = $j.trim(q.find(".telephone").get(0).options[q.find(".telephone").get(0).selectedIndex].value);
				if(q.find(".telephone").get(0).selectedIndex != '0'){
					if(an == 1){
						sql+=" and ";
						an = 1;
					}
					if(s == 0){
						sql += "or (";
						s = 1;  //表示union后的左半括号存在
						an = 1;//表示该条件之后的条件要加and
					}
					if(tmp == 1){
		       		sql += "student.studenttelephone is not null";
					
					}
					else if(tmp == 2){
					sql += "student.studenttelephone is null";
					}
				}
				//-----------------学院
				tmp = $j.trim(q.find(".seleCollege").get(0).options[q.find(".seleCollege").get(0).selectedIndex].value);
				if(q.find(".seleCollege").get(0).selectedIndex != '0'){
					if(an == 1){
						sql+=" and ";
						an = 1;
					}
					if(s == 0){
						sql += "or (";
						s = 1;  //表示union后的左半括号存在
						an = 1;//表示该条件之后的条件要加and
					}
					
					sql += "student.collegeinfoid = "+ tmp;
				}
				//--------------专业
				tmp = $j.trim(q.find(".seleMajor").get(0).options[q.find(".seleMajor").get(0).selectedIndex].value);
				if(q.find(".seleMajor").get(0).selectedIndex != '0'){
					if(an == 1){
						sql+=" and ";
						an = 1;
					}
					if(s == 0){
						sql += "or (";
						s = 1;  //表示union后的左半括号存在
						an = 1;//表示该条件之后的条件要加and
					}
					
					sql += "student.majorinfoid = "+ tmp;
				}
				//----------班级
				tmp = $j.trim(q.find(".txtClass").get(0).value);
				if(tmp != ""){
					if(an == 1){
						sql+=" and ";
						an = 1;
					}
					if(s == 0){
						sql += "or (";
						s = 1;  //表示union后的左半括号存在
						an = 1;//表示该条件之后的条件要加and
					}
					
					sql += "student.studentclass like '%"+ tmp +"%'";
				}
				
				//-----------类别
				tmp = $j.trim(q.find(".seleType").get(0).options[q.find(".seleType").get(0).selectedIndex].value);
				if(q.find(".seleType").get(0).selectedIndex != '0'){
					if(an == 1){
						sql+=" and ";
						an = 1;
					}
					if(s == 0){
						sql += "or (";
						s = 1;  //表示union后的左半括号存在
						an = 1;//表示该条件之后的条件要加and
					}
					
					sql += "student.studenttype = '"+ tmp + "'";
				}
				//-----------入学年份
				tmp = $j.trim(q.find(".seleEnrollYear").get(0).options[q.find(".seleEnrollYear").get(0).selectedIndex].value);
				if(q.find(".seleEnrollYear").get(0).selectedIndex != '0'){
					if(an == 1){
						sql+=" and ";
						an = 1;
					}
					if(s == 0){
						sql += "or (";
						s = 1;  //表示union后的左半括号存在
						an = 1;//表示该条件之后的条件要加and
					}
					
					sql += "student.studentenrollyear = '"+ tmp + "'";
				}
				//-----------学制
				tmp = $j.trim(q.find(".seleEducationYear").get(0).options[q.find(".seleEducationYear").get(0).selectedIndex].value);
				if(q.find(".seleEducationYear").get(0).selectedIndex != '0'){
					if(an == 1){
						sql+=" and ";
						an = 1;
					}
					if(s == 0){
						sql += "or (";
						s = 1;  //表示union后的左半括号存在
						an = 1;//表示该条件之后的条件要加and
					}
					
					sql += "student.studenteducationyears = '"+ tmp + "'";
				}
				//-----------培养方式
				tmp = $j.trim(q.find(".seleAdmissionType").get(0).options[q.find(".seleAdmissionType").get(0).selectedIndex].value);
				if(q.find(".seleAdmissionType").get(0).selectedIndex != '0'){
					if(an == 1){
						sql+=" and ";
						an = 1;
					}
					if(s == 0){
						sql += "or (";
						s = 1;  //表示union后的左半括号存在
						an = 1;//表示该条件之后的条件要加and
					}
					
					sql += "student.studentadmissiontype = '"+ tmp + "'";
				}
				
				//----------导师
				tmp = $j.trim(q.find(".txtAdvisorName").get(0).value);
				if(tmp != ""){
					if(an == 1){
						sql+=" and ";
						an = 1;
					}
					if(s == 0){
						sql += "or (";
						s = 1;  //表示union后的左半括号存在
						an = 1;//表示该条件之后的条件要加and
					}
					
					sql += "student.studentadvisorname like '%"+ tmp +"%'";
				}
				//----------备注
				tmp = $j.trim(q.find(".txtMsc").get(0).value);
				if(tmp != ""){
					if(an == 1){
						sql+=" and ";
						an = 1;
					}
					if(s == 0){
						sql += "or (";
						s = 1;  //表示union后的左半括号存在
						an = 1;//表示该条件之后的条件要加and
					}
					
					sql += "student.studentmisc like '%"+ tmp +"%'";
				}
				//宿舍状态:空或非空,空,非空
				tmp = tmp = $j.trim(q.find(".seleDormStatus").get(0).options[q.find(".seleDormStatus").get(0).selectedIndex].value);
				if(tmp == "notBlank"){
					if(an == 1){
						sql += " and ";
						an = 1;
					}
					if(s == 0){
						sql += "or (";
						s = 1;
						an = 1;
					}
					sql += "studentbedlink.studentid = student.studentid and studentbedlink.dormitoryid = dormitory.dormitoryid ";
				}
				if(tmp == "blank"){
					if(an == 1){
						sql += " and ";
						an = 1;
					}
					if(s == 0){
						sql += "or (";
						s = 1;
						an = 1;
					}
					sql += "(student.studentid,dormitory.dormitoryid) not in (select studentbedlink.studentid,studentbedlink.dormitoryid from studentbedlink) ";
				}
				//-----------公寓

				if(q.find(".seleApartment").get(0).disabled == false && q.find(".seleApartment").get(0).selectedIndex != '0'){
					tmp = $j.trim(q.find(".seleApartment").get(0).options[q.find(".seleApartment").get(0).selectedIndex].value);
					if(an == 1){
						sql+=" and ";
						an = 1;
					}
					if(s == 0){
						sql += "or (";
						s = 1;  //表示union后的左半括号存在
						an = 1;//表示该条件之后的条件要加and
					}
					
					sql += "dormitory.apartmentid = "+ tmp;
				}
				//-----------楼层

				if(q.find(".seleFloorno").get(0).disabled == false && q.find(".seleFloorno").get(0).selectedIndex != '0'){
					tmp = $j.trim(q.find(".seleFloorno").get(0).options[q.find(".seleFloorno").get(0).selectedIndex].value);
					if(an == 1){
						sql+=" and ";
						an = 1;
					}
					if(s == 0){
						sql += "or (";
						s = 1;  //表示union后的左半括号存在
						an = 1;//表示该条件之后的条件要加and
					}
					
					sql += "dormitory.dormitoryfloorno = "+ tmp;
				}
				//----------宿舍号
				tmp = $j.trim(q.find(".txtDorm").get(0).value);
				if(q.find(".txtDorm").get(0).disabled == false && tmp != ""){
					
					if(an == 1){
						sql+=" and ";
						an = 1;
					}
					if(s == 0){
						sql += "or (";
						s = 1;  //表示union后的左半括号存在
						an = 1;//表示该条件之后的条件要加and
					}
					
					sql += "dormitory.dormitoryname like '%"+ tmp +"%'";
				}
				//-----------标记
				tmp = $j.trim(q.find(".seleStudentLabel").get(0).options[q.find(".seleStudentLabel").get(0).selectedIndex].value);
				if(q.find(".seleStudentLabel").get(0).selectedIndex != '0'){
					if(an == 1){
						sql+=" and ";
						an = 1;
					}
					if(s == 0){
						sql += "or (";
						s = 1;  //表示union后的左半括号存在
						an = 1;//表示该条件之后的条件要加and
					}
					
					sql += "student.studentpreasignedid = '"+ tmp + "'";
				}
				//-----------项目
				if(q.find(".seleField").get(0).selectedIndex != '0'){
					if(an == 1){
						sql+=" and ";
						an = 1;
					}
					if(s == 0){
						sql += "or (";
						s = 1;  //表示union后的左半括号存在
						an = 1;//表示该条件之后的条件要加and
					}
					var o;
					switch(q.find(".seleField").get(0).selectedIndex){
						case 1 : o = "studentbirthday";break;
						case 2 : o = "studentidentitycardno";break;
						case 3 : o = "studentbirthplace";break;
						case 4 : o = "studentethnic";break;
						case 5 : o = "studenttelephone";break;
						case 6 : o = "studentarchivesaddress";break;
						case 7 : o = "studentnickname";break;
						case 8 : o = "studentemail";break;
						case 9 : o = "studentpolitics";break;
						case 10 : o = "studentmiddleschool";break;
						case 11 : o = "studentsecondlanguage";break;
						case 12 : o = "studentycsj";break;
						case 13 : o = "studentgraduateschool";break;
						case 14 : o = "studentgraduatedate";break;
						case 15 : o = "studentflfx";break;
					}
					tmp = $j.trim(q.find(".txtField").get(0).value);
					if(tmp != ""){
						sql = sql + "student." + o + " like '%"+ tmp + "%'";
					}
				}
				
				//--------补齐最后的右括号
				if(s == 1){
					sql += ") ";
				}
				
				//------------条件结束----------
			}
			//alert(sql);
			renderConditionStudentSearchPage();
		}
		
		//高级查询学生页面显示
		function renderConditionStudentSearchPage(){
			sidList.length = 0;
			searchTotalCount(sql);
		}
		//查询总行数，计算分页的页数，并在回调中查询显示第一页的数据
		function　searchTotalCount(sql){
			studentAction.getStudentBySQLSearchConditionsRows(sql,function (totalRecords){
				
				
					$('div_selectAllPage').style.display = "none";  //隐藏'全选所有页'
					$('div_basicInfo').style.display = 'none';
					$('dataTable').style.display = 'none'; 
					$('pageTable').style.display = 'none';
					
					
				
				if(totalRecords == 0){
					alert("查询结果为空!"); 
					return;
				}
				totalCount = totalRecords;
				$('div_selectAllPage').style.display = "";
				$('selectAllInEveryPage').checked = false;    //全选所有页选项初始化时为false;
				$('div_basicInfo').style.display = "";
				$j('#dataTable').show(500);
				$('pageTable').style.display = '';
				
			
				
				studentAction.getStudentBySQLSearchConditionsPerPage(1,totalCount,sql,renderstudentcallback);
			});
		}
		var renderstudentcallback = function setStudentSearchPage(stulist){
			//studentList = stulist;
			if(stulist==null){
				alert("查询到的学生结果为空！");
				return;
			}
			if($('dataTable').style.visibility == 'hidden'){
				$('dataTable').style.visibility = 'visible';
			}
			if($('pageTable').style.visibility == 'hidden'){
				$('pageTable').style.visibility = 'visible';
			}
			
			DWRUtil.removeAllRows('ttb', { filter:function(tr) {
			      return (tr.id != "pattern");
				    }});
			      ////===============fengexian====
			 var stud, id;
			//alert(stulist[0][0]);
			 for (var i =0; i < stulist.length ; i++) {
				 stud = stulist[i];
			     id = stud[0];
			     dwr.util.cloneNode("pattern", { idSuffix:id });
			     dwr.util.setValue("tableid" + id, stud[0]);
			     dwr.util.setValue("tableno" + id, stud[1]);
			     dwr.util.setValue("tablename" + id, stud[2]);
			     dwr.util.setValue("tablesex" + id, stud[3]);
			      
			       if('object' == typeof(stud[4])){
			      		 dwr.util.setValue("tableclass" + id, "");
			      }else{
			     		 dwr.util.setValue("tableclass" + id, stud[4]);
			      }
			      
			       if('object' == typeof(stud[5])){
			      		 dwr.util.setValue("tablecollegename" + id, "");
			      }else{
			     		 dwr.util.setValue("tablecollegename" + id, stud[5]);
			      }
			      
			      if('object' == typeof(stud[6])){
			      		 dwr.util.setValue("tablemajorname" + id, "");
			      }else{
			     		 dwr.util.setValue("tablemajorname" + id, stud[6]);
			      }
			      
			      if('object' == typeof(stud[7])){
			      		 dwr.util.setValue("tabledormitory" + id, "");
			      		 
			      }else{
			     		 dwr.util.setValue("tabledormitory" + id, stud[7]);
			      }
			      if('object' == typeof(stud[8])){
			      		 dwr.util.setValue("tablepreassignid" + id, "");
			      		 
			      }else{
			     		 dwr.util.setValue("tablepreassignid" + id, stud[8]);
			      }
			      dwr.util.setValue("cbx" + id, stud[0]);
 				 dwr.util.setValue("tel" + id, stud[9]);
  			   	 $("pattern" + id).style.display= "";
	             stuCache[id] = stulist;
			   }
				setPageInfo();
				tbCSS();
			}
		function setPageInfo(){
        $('pageTd').innerHTML = '';
        studentAction.getPage({     
            callback:function(data){
                page = data;
                if(page.totalPage != 0){
                    var pageSpan = document.createElement('span');
                    pageSpan.innerHTML = '共 '+totalCount+' 条 '+'   第 '+page.currentPage+' 页    共'+page.totalPage+' 页 ';
                    $('pageTd').appendChild(pageSpan);
                    var aFirst = document.createElement('a');
                    aFirst.setAttribute('href','javascript:getFirstData()');
                    aFirst.innerHTML = '首页';
                    $('pageTd').appendChild(aFirst);
                    var aPrevious = document.createElement('a');
                    aPrevious.setAttribute('href','javascript:getPreviousData()');
                    aPrevious.innerHTML = '上一页 ';
                    $('pageTd').appendChild(aPrevious);
                    var aNext = document.createElement('a');
                    aNext.setAttribute('href','javascript:getNextData()');
                    aNext.innerHTML = '下一页 ';
                    $('pageTd').appendChild(aNext);
                    var aLast = document.createElement('a');
                    aLast.setAttribute('href','javascript:getLastData()');
                    aLast.innerHTML = '尾页';
                    $('pageTd').appendChild(aLast);    
                }               
            }
        });
        $('loading').style.display = 'none';
        judgeCheckboxInNewPage();
		$('flagcbx').checked = false;
		setRowColor($('dataTable'),'row_odd','row_even');
    }   

		function getFirstData(){
			page.currentPage = 1;
			getDataPerPage();
		}
		
		 function getPreviousData(){
        if(page.currentPage>1){
            page.currentPage--;
        }
        getDataPerPage();
  	  }
    
    	function getNextData(){
        if(page.currentPage<page.totalPage){
            page.currentPage++;
        }
        getDataPerPage();
   	 }
		
		function getLastData(){
			page.currentPage = page.totalPage;
			getDataPerPage();
		}
		
		
		function getDataPerPage(){
			$('loading').style.display = 'block';
			//alert(page.currentPage);
			//alert(s_sql);
			studentAction.getStudentBySQLSearchConditionsPerPage(page.currentPage,totalCount, sql,renderstudentcallback);
		}	
		 //dwr分页中，当进入到新的页面时判断当前页的checkbox是否曾经被选中，并存入了studentList中
		function judgeCheckboxInNewPage(){
			var a=document.getElementsByTagName("input");  
			//alert(studentidList.length+"**"+studentidList)
        	for(var i=0;i<a.length;i++){  
               if(a[i].type=='checkbox' && a[i].id != 'selectAllInEveryPage'){  
              	  if(sidList.length == 0){
              	  	 a[i].checked = false;
              	  }
                  for(var b=0;b<sidList.length;b++){
                  	if(a[i].id.substr(3) == sidList[b]){
                  		a[i].checked = true;
                  		break;
                  	}
                  	if(b == sidList.length - 1){
                  		a[i].checked = false;
                  	}
                  	else {
                  		continue;
                  	}
                  }
              }
            }
		}
		
		//全选所有查询到的学生
       function selectAllSearched(){
       		if($('selectAllInEveryPage').checked == true){
       			studentAction.getStudentTelBySQL(sql,getStudentBySQLCallback);
       		}else {
       			sidList.length = 0;
       			selectNonecbx();
       		}
       
       }
       //全选所有查询到的学生回调函数
       var getStudentBySQLCallback = function getStudentBySQLCallbackFunc(sList){
       		sidList.length = 0;
       		
       		for(var a = 0; a<sList.length; a++){
       		    var sl = sList[a];
       			sidList[sidList.length] = sl[0];
       		    stelList[stelList.length] = sl[2];

       		//*****************************************************************
       		}
       		selectAllcbx();
       }
		//均不选所有的checkbox
		function selectNonecbx(){
			var  a=document.getElementsByTagName("input");  
        	for(var i=0;i<a.length;i++){  
              if(a[i].type=='checkbox'){  
              	  if(a[i].id == "cbx"){
              	  	continue;
              	  }
                  a[i].checked = false ;
                  for(var b=0;b<sidList.length;b++){
                  	if(a[i].id.substr(3) == sidList[b]){
                  		sidList.splice(b,1);
                  		stelList.splice(b,1);
                  		       		//*****************************************************************
                  		
                  		break;
                  	}
                  	else continue;
                  }
              }  
            }  
           // alert(studentidList.length)
        } 
        //全选所有的checkbox
		function selectAllcbx(){
			var   a=document.getElementsByTagName("input");  
			//alert($('cbx').checked);
        	for(var i=0;i<a.length;i++){  
              if(a[i].type=='checkbox'){
              	  if(a[i].id == "cbx" || a[i].id == "flagcbx"|| a[i].id == "selectAllInEveryPage"){
              	  	continue;
              	  	
              	  }
              	  a[i].checked = true ;
              	  if(sidList.length == 0){
              	  	sidList[0] = a[i].id.substr(3);
              	  	stelList[0] = $("tel"+a[i].id.substr(3)).value;
              	  	
              	  	//******************************************************************************************
              	  }
              	  for(var b=0;b<sidList.length;b++){
                  	if(a[i].id.substr(3) == sidList[b])
                  		break;
                  	else if(b == sidList.length-1){
                  		sidList[sidList.length] = a[i].id.substr(3);
                  		stelList[stelList.length] =  $("tel"+a[i].id.substr(3)).value;
                  		
              	 // ******************************************************************************************
                  	}
                  }
              }
            }  
           // alert(studentidList.length+"#"+studentidList);
        } 
        //当作为全选标志的checkbox被选中的时候，当前页所有学生被选中，反之则全不选中
       function checkForSelectAll(){
       		if($('flagcbx').checked == true){
       			selectAllcbx();
       		}else{
       			selectNonecbx();
       		}
       }  
       
       
       function updateStudentidList(obj){
        	$('selectAllInEveryPage').checked = false;
        	if(obj.checked==true){
        		sidList[sidList.length] = obj.id.substr(3);
                stelList[stelList.length] =  $("tel"+obj.id.substr(3)).value;
        		
        	//******************************************************************************************
        		
        	}
        	if(obj.checked==false){
        		for(var i=0;i<sidList.length;i++){
        			if(obj.id.substr(3) == sidList[i]){
        				sidList.splice(i,1);
        				stelList.splice(i,1);
        				       		//*****************************************************************
        				
        			}
        		}
        	}
        }

				
		//确定按钮的事件处理方法
		function confirm(){
			var parentDoc = window.dialogArguments;
			var selectPhoneNos = parentDoc.getElementById("selectPhoneNos");
			var currentOptions = "";
			if(stelList.length > 0){
			for(var i=0; i< stelList.length-1; i++){
			 currentOptions += stelList[i]+",";
			}
			  currentOptions += stelList[stelList.length-1];
			}
			if(currentOptions.length > 0){
			    selectPhoneNos.appendChild(createOptionNode(parentDoc,"查询结果",currentOptions));
				window.close();
			}else{
				alert("请选择联系人！");
				return;
			}
		}
		 
		
		function createOptionNode(doc,value,key){
			var optionNode = doc.createElement("<option>");
			var textNode = doc.createTextNode(value);
			optionNode.setAttribute("value",key);
			optionNode.appendChild(textNode);
			return optionNode;			
		}

       //单击查询到的学生的某一行时，在页面的下方显示学生的基本信息
       function getStudentInfoByNo(obj){
       		var id = obj.id.substr(7);
       		//alert("id:" + id + "$$$tableno:" + $('tableno' + id).innerHTML)
       		$('student_info').value = $('tableno' + id).innerHTML;
       		stu_BasicInfo();
       }
//-----------------------自定义函数结束-------------------		
		
		
		
		</script>
	</head>
	<body>
		<h3  style="text-align: left;">高级搜索</h3>
		<div id="condition" class="divCondition" style="text-align: left;">
			<div id="item"  style="display:none;background-color:#EFefef" class="divItem">
				<br/>
				<div>
					<label>学号</label>
					<input type="text" class="txtNo">
					<label>姓名</label>
					<input type="text" class="txtName">
					<label>性别</label>
					<select class="seleGender">
						<option>不限</option>
						<option value="男">男</option>
						<option value="女">女</option>
					</select>
					<input type="button" class="btnAdd" value=" + " onclick='newItem("#item","#condition")'/>
					<input type="button" class="btnSubtract" value=" - " onclick='deleteItem(this)'/>
					
				</div>
				<div>
					<label>学院</label>
					<select class="seleCollege" style="width: 153px;" onchange="selectedCollegeChange(this)" >
						<option>不限学院</option>
					</select>
					
					<label>专业</label>
					<select class="seleMajor" style="width: 153px;" onchange="selectedMajorChange(this)">
						<option>不限专业</option>
					</select>
					
					<label>班级</label>
					<input type="text" class="txtClass" />
					
					
				</div>
				<div>
					<label>导师</label>
					<input type="text" class="txtAdvisorName">
					<label>备注</label>
					<input type="text" class="txtMsc">
				</div>
				<div>
					<label>类别</label>
					<select class="seleType" style="width: 95px;">
						<option>不限</option>
						<option value="本科">本科</option>
						<option value="硕士">硕士</option>
						<option value="博士">博士</option>
					</select>
					<select class="seleEnrollYear" style="width: 84px;">
						<option>入学年份</option>
						<option value="2003">2003</option>
						<option value="2004">2004</option>
						<option value="2005">2005</option>
						<option value="2006">2006</option>
						<option value="2007">2007</option>
						<option value="2008">2008</option>
						<option value="2009">2009</option>
						<option value="2010">2010</option>
						<option value="2011">2011</option>
					</select>
					<select class="seleEducationYear" style="width: 90px;">
						<option>学制</option>
						<option value="3">3</option>
						<option value="4">4</option>
						<option value="5">5</option>
					</select>
					<select class="seleAdmissionType" style="width: 90px;">
						<option>培养方式</option>
						<option value="非定向">非定向</option>
						<option value="定向">定向</option>
						<option value="委培">委培</option>
						<option value="自筹">自筹</option>
					</select>
				</div>
				
				<div>
					<label>宿舍 </label>
					<select class="seleDormStatus" style="width: 78px;" onchange="DormStatusChange(this)">
						<option >空或非空</option>
						<option value="blank">空</option>
						<option value="notBlank">非空</option>
					</select>
					<select class="seleApartment" style="width: 95px;" onchange="apartmentChange(this)">
						<option>公寓号</option>
					</select>
					<select class="seleFloorno" style="width: 84px;">
						<option>不限楼层</option>
					</select>
					<label>宿舍号</label>
					<input type="text" class="txtDorm">
					<label>标记</label>
					<select class="seleStudentLabel" style="width: 105px;">
						<option>分配标记</option>
					</select>
				</div>
				<div>
					<label>项目</label>
					<select class="seleField" style="width: 183px;">
						<option>选择字段</option>
						<option>生日</option>
						<option>身份证号</option>
						<option>生源地</option>
						<option>民族</option>
						<option>电话</option>
						<option>档案所在地</option>
						<option>昵称</option>
						<option>Email</option>
						<option>政治面貌</option>
						<option>毕业中学</option>
						<option>外语</option>
						<option>因材施教 如:专转本(高职)</option>
						<option>毕业大学 </option>
						<option>毕业时间</option>
						<option>分流方向 如：在校新生</option>
					</select>
					<input type="text" class="txtField">
					<label>是否有电话</label>
					<select class="telephone">
						<option>不限</option>
						<option value="1">有</option>
						<option value="2">没有</option>
					</select>
				</div>
				<!--  
				<div style="color:red">————————————————————————————————————————————————</div>
				-->
				<br/>
			</div> <!-- item div end  -->
			
		</div> <!-- condition div  end  -->
		
		<div>
			<input type="button" id="btnSearch" value="查询" onclick="search()"/>
		</div>
		<br/>
		<div>
			<span id="div_selectAllPage" style="display:none;float: left; ">
					<input type="checkbox" id="flagcbx" onclick="checkForSelectAll()"/>
					选择当前页
					<input type="checkbox" id="selectAllInEveryPage" onclick="selectAllSearched()" />
					全选所有页
			</span>
			<!-- 学生预分配 -->
			
				
				
		<div>		
			<table  id="dataTable" style="visibility: hidden" class="sortable scrolltable table_list_style table_common" rowclass="row_odd,row_even"
						style="visibility: hidden" width="640px;">
					<thead>
						<tr>
							<th class="sorttable_nosort" width="15px">
								
							</th>
							<th width="60px">
								学号
							</th>
							<th width="45px">
								姓名
							</th>
							<th width="35px">
								性别
							</th>
							<th width="130px">
								学院
							</th>
							<th width="120px">
								专业
							</th>
							<th width="80px">
								班级
							</th>
							<th width="120px">
								宿舍
							</th>
							<th width="50px">
								预分配
							</th>
						</tr>
					</thead>
					<tbody id="ttb">
						<tr id="pattern" style="display: none"
							onclick="getStudentInfoByNo(this)">
							<td>
								<input type="checkbox" id="cbx" name="cbx"
									onclick="updateStudentidList(this)" />
							</td>
							<td>
								<span id="tableno">id</span>
							</td>
							<td width="45px">
								<span id="tablename">name</span>
							</td>
							<td>
								<span id="tablesex">sex</span>
							</td>
							<td>
								<span id="tablecollegename">collegename</span>
							</td>
							<td>
								<span id="tablemajorname">majorname</span>
							</td>
							<td>
								<span id="tableclass">class</span>
							</td>
							<td>
								<span id="tabledormitory">dormitory</span>
							</td>
							<td width="50px">
								<span id="tablepreassignid">preassignid</span>
							</td>
							<td>
							<input type="hidden" id="tel">
							</td> 
					</tbody>
			</table>
		</div>
		<div>
			<table id="pageTable" align="center"
						style="visibility: hidden;">
						<tr>
							<td id="pageTd">
							</td>
						</tr>
			</table>
		</div>
		<div id="loading"
					style="display: none; text-align: center; color: red; font: 13px;">
					Loading...
		</div>
		<div style="display: none;" id="div_basicInfo">
				<hr size="1" width="95%" />
				<jsp:include page="/student/basicstudentinfo_advancedSearch.jsp"></jsp:include>
		</div>
		<div class="Submit">
					<input name="Submit" type="button" class="Button"
						onClick="javascript:confirm();" value="确定">
					<input name="Submit" onClick="javascript:window.close();"
						type="button" class="Button" value="关闭">
				</div>

		
	</body>
</html>

			
		
